import com.dao.BlogMapper;
import com.pojo.Blog;
import com.utils.IdUtils;
import com.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class test {
    @Test
    public  void  testIf(){
        Map<String,String > map =new HashMap<String, String>();
        map.put("title","C语言从入门到放弃");
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        List<Blog> blogs = sqlSession.getMapper(BlogMapper.class).find_With_If(map);
        for (Blog blog : blogs) {
            System.out.println(blog);
        }

    }
    @Test
    public void testAdd(){
        Blog blog=new Blog();
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);

        blog.setId(IdUtils.getId());
        blog.setTitle("C语言从入门到放弃");
        blog.setAuthor("Mr.Wei");
        blog.setCreateTime(new Date());
        blog.setViews(999);
        mapper.add(blog);

        blog.setTitle("Java从入门到入土");
        blog.setAuthor("Mr.Wang");
        blog.setId(IdUtils.getId());
        mapper.add(blog);

        blog.setTitle("Python从入门到出门");
        blog.setAuthor("Mr.Fu");
        blog.setId(IdUtils.getId());
        mapper.add(blog);

        blog.setTitle("Spring从入门到入狱");
        blog.setAuthor("Mr.Chen");
        blog.setId(IdUtils.getId());
        mapper.add(blog);

    }
    @Test
    public void testfindAllBlog(){
        for (Blog allBlog : MybatisUtils.getSqlSession().getMapper(BlogMapper.class).findAllBlogs()) {
            System.out.println(allBlog);
        }
    }
}
